/*
 * main.cpp
 *
 *  Created on: 2011-3-3
 *      Author: tom
 */

#include "geoTrans.h"
#include "enhancement.h"
#include "dft.h"
#include "adpMedFilter.h"
#include "restoration.h"
#include "segmentation.h"
#include <getopt.h>
#include <sstream>
#include <iostream>
using std::stringstream;
using std::cout;

int main(int argc,char** argv){
	IplImage* image=0;
	stringstream s;
	GeoTrans* g=0;
	Enhancement* e=0;
	option longopts[]={{"zoom",1,0,'z'},{"rotate",1,0,'r'},{"mirror",0,0,'m'},{"flip",0,0,'p'},{"histogram",0,0,'h'},{"laplace",0,0,'l'},
						{"gaussian",0,0,'g'},{"file",1,0,'f'},{"dft",0,0,'d'},{"vector",0,0,'v'},{"adaptive",0,0,'a'},{"impluse",0,0,'i'},
						{"guassian_noise",0,0,'n'},{"canny",0,0,'c'},{"sobel",0,0,'s'},{"threshold",0,0,'t'},{"region",0,0,'o'},{"line",0,0,'e'}};
	int opt;

	while((opt=getopt_long(argc,argv,":f:z:r:mphlgdvaincstoe",longopts,0))!=-1){
		switch(opt){
		case 'f':
			image=cvLoadImage(optarg);
			if(image==0)
				return -1;
			g=new GeoTrans(image);
			e=new Enhancement(image);
			break;
		case 'z':
			s<<optarg;
			double scalar;
			s>>scalar;
			g->zoom(scalar);
			break;
		case 'r':
			s<<optarg;
			double angle;
			s>>angle;
			g->rotate(angle);
			break;
		case 'm':
			g->mirror();
			break;
		case 'p':
			g->flip();
			break;
		case 'h':
			e->hEqualization();
			break;
		case 'l':
			e->lSharpen();
			break;
		case 'g':
			e->gFilter();
			break;
		case 'd':
			dft(image);
			break;
		case 'v':
			system("./dura");
			break;
		case 'a':
			adaptiveMediaFilter(image);
			break;
		case 'i':
			impulse_noise(image);
			break;
		case 'n':
			gaussian_noise(image);
			break;
		case 'c':
			edgeDectectionGaussian(image);
			break;
		case 's':
			edgeDectectionSobel(image);
			break;
		case 't':
			thresholdSegmentation(image);
			break;
		case 'o':
			regionGrowing(image);
			break;
		case 'e':
			system("./line");
			break;
		case ':':
			cout<<"option needed!!\n";
			break;
		case '?':
			cout<<"unrecognized option!!\n";
			break;
		}
	}

	if(e)
		delete e;
	if(g)
		delete g;
	if(image)
		cvReleaseImage(&image);
	return 0;
}
